package com.itheima.reverseIndex;

import com.itheima.friend.Friend1MapperTask;
import com.itheima.friend.Friend1ReducerTask;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;

public class ReverseIndexMain extends Configured implements Tool {
    @Override
    public int run(String[] strings) throws Exception {
        Job job = Job.getInstance(super.getConf(),"ReverseIndexMain");

        job.setJarByClass(ReverseIndexMain.class);

        job.setInputFormatClass(TextInputFormat.class);
        TextInputFormat.addInputPath(job,new Path("C:\\Users\\86186\\Desktop\\input"));

        job.setMapperClass(ReverseIndexMapperTask.class);
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(IntWritable.class);

        job.setReducerClass(ReverseIndexReducerTask.class);
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);

        job.setOutputFormatClass(TextOutputFormat.class);
        TextOutputFormat.setOutputPath(job,new Path("C:\\Users\\86186\\Desktop\\ReverseIndexoutput"));

        boolean flag = job.waitForCompletion(true);
        return flag ? 0:1;
    }

    public static void main(String[] args) throws Exception{
        int i = ToolRunner.run(new Configuration(), new ReverseIndexMain(), args);
        System.exit(i);
    }
}
